package com.kitty.game.utils;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.chat.message.RespChat;
import com.kitty.game.mail.model.Mail;
import com.kitty.game.mail.service.MailService;
import com.kitty.game.role.model.Role;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.message.Message;
import com.kitty.mina.message.MessagePusher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SenderUtils {
    private static Logger logger = LoggerFactory.getLogger(SenderUtils.class);

    public static void brodCastMessage(Message message, String type) {// 类型 npc role
        if (type.equals("npc")) {
            DataCache.ONLINE_ROLES.values().forEach(role -> MessagePusher.pushMessage(role, message));
        }
    }


    /**
     * 发送邮件
     */
    public static void sendMail(Role role ,Mail mail) {
        MailService mailService = SpringUtils.getBean(MailService.class);
        mailService.sendNewMail(role, mail);
    }


    /**发送消息*/
    public static void pushChatMessage(RespChat respChat){
        DataCache.ONLINE_ROLES.values().forEach(role -> MessagePusher.pushMessage(role,respChat));
    }
    public static void pushChatMessage2GM(RespChat respChat){
        DataCache.ONLINE_GM.values().forEach(role -> MessagePusher.pushMessage(role,respChat));
    }

    /**发帮派聊天消息*/
    public static void pushPartyChatMessage(long partyId, RespChat respChat) {
        /**同一个帮派才能看到*/
        DataCache.ONLINE_ROLES.values().forEach(onlineRole -> {
            if (partyId != onlineRole.getPartyId()) {
                return ;
            }
            MessagePusher.pushMessage(onlineRole, respChat);
        });
    }

    //结婚
    public static void sendAllOnlinePlayers(Message message) {
        DataCache.ONLINE_ROLES.values().forEach(role -> MessagePusher.pushMessage(role, message));
    }
}